package thread;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @author ZhuQi
 * @ClassName FutureTaskDemo
 * @Date 2022/9/5 11:11
 * @Version 1.0
 * @Description 测试 FutureTask
 */
@Slf4j
public class FutureTaskDemo {
    @SneakyThrows
    public static void main(String[] args) {
        FutureTask<String> stringFutureTask = new FutureTask<>(new MyTask());
        new Thread(stringFutureTask, "t1").start();
        while (true) {
            if (stringFutureTask.isDone()) {
                String s = stringFutureTask.get();
                log.info(s);
                break;
            }
        }
    }
}

class MyTask implements Callable<String> {

    @Override
    public String call() throws Exception {
        return "call";
    }
}